package com.fangda.network.udp;

import com.fangda.network.NetworkConfig;
import com.fangda.network.NetworkProvider;
import io.vertx.core.Vertx;
import io.vertx.core.datagram.DatagramSocket;
import io.vertx.core.datagram.DatagramSocketOptions;

public class UdpProvider implements NetworkProvider<UdpNetwork> {
	
    @Override
    public UdpNetwork createNetwork(Vertx vertx, String id, NetworkConfig networkConfig) {
        DatagramSocketOptions options = (DatagramSocketOptions)networkConfig.getConfig().get("options");
        if(options == null) {
            options = new DatagramSocketOptions();
        }
        DatagramSocket socket = vertx.createDatagramSocket(options);
        UdpNetwork network = new UdpNetwork(id, networkConfig);
        network.setSocket(socket);
        return network;
    }
}
